package simulation;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;


/**
 * This class is responsible for instantiating all of the objects on the screen
 * from provided data files.
 * 
 */
public abstract class Factory {

    /**
     * Determines which type of object to create and adds it to the model.
     */
    public void loadModel (Model model, File modelFile) {
        try {
            Scanner input = new Scanner(modelFile);
            while (input.hasNext()) {
                Scanner line = new Scanner(input.nextLine());
                if (line.hasNext()) {
                    String type = line.next();
                    loadObjects(model, line, type);
                }
            }
            input.close();
        }
        catch (FileNotFoundException e) {
            // should not happen because File came from user selection
            e.printStackTrace();
        }
    }

    /**
     * Creates instances of objects depending on the line read in.
     */
    protected abstract void loadObjects (Model model, Scanner line, String type);

}
